const express = require('express');
const app = express();
const _ = require('lodash');
// //获取客户端 ip 地址   
app.use(function (request, response, next) {
    // access 访问进入  control 控制  allow 允许  origin 源
    response.setHeader('Access-Control-Allow-Origin', "*"); //允许跨域请求
    response.setHeader('Access-Control-Allow-Headers', "*"); //该响应头 允许客户端可以设置『自定义』请求头
    response.setHeader('Access-Control-Allow-Methods', "*"); //允许各种请求方式进行跨域请求
    response.setHeader('Access-Control-Expose-Headers', "*"); //暴露响应头信息
    response.setHeader("Access-Control-Max-Age", 0); // 设置有效时间 单位是『秒』,最大值为 600
    next();
});

// app.options('*', (req, res) => {
//     res.status(200).send('');
// });

//设置网站根目录
app.use(express.static('./public'));

// http://192.168.20.111/api
app.get('/api', (req, res) => {
    return res.json({
        "id": 4666,
        "uuid": "ae97af26-231f-4b62-ae6a-92db4dff4c20",
        "hitokoto": "明月装饰了你的窗子，你装饰了别人的梦。",
        "type": "g",
        "from": "断章",
        "from_who": null,
        "creator": "smallxu",
        "creator_uid": 2639,
        "reviewer": 1044,
        "commit_from": "web",
        "created_at": "1569328047",
        "length": 19
    })
})

app.listen(80, () => {
    console.log('服务已经启动....');
});